/*************************************************************************
    > File Name: myprocess.c
    > Author: ma6174
    > Mail: ma6174@163.com 
    > Created Time: Wed 29 Oct 2025 09:07:34 AM CST
 ************************************************************************/

#include <stdio.h>
#include <unistd.h>

int main()
{
	printf("父进程运行: pid: %d, ppid:%d\n", getpid(), getppid());

	pid_t id = fork();
	if(id == 0)
	{
	    // 子进程
	    int cnt = 10;
	    while(cnt)
	    {
	        printf("我是子进程,我的pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt);
	        sleep(2);
	        cnt--;
	    }
	}
	else
	{
	    // 父进程
	    while(1)
	    {
	        printf("我是父进程,我的pid: %d, ppid: %d\n", getpid(), getppid());
	        sleep(1);
	    }
	}
	return 0;
}
